package com.taotao.rop.database.domain;

import com.taotao.admin.pojo.WechatRequestForExport;
import com.taotao.rop.database.Constant;
import com.taotao.wechat.util.MessageUtil;
import org.apache.commons.lang.StringUtils;

import java.util.Date;
import java.util.Map;

public class WechatRequest extends Page {
    private Long id;
    private Long userId;
    private Long respId;
    private String msgType;
    private String content;
    private String picUrl;
    private String mediaId; //存储openId
    private String format;
    private String thumbMediaid;
    private Double locationX;
    private Double locationY;
    private Double scale;
    private String label;
    private String title;
    private String description;
    private String url;
    private String msgId;   //存储appId
    private Date createTime;
    private String event;
    private String eventkey;
    private String respmsg;

    //扩展字段
    private Date startTime;
    private Date endTime;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getRespId() {
        return respId;
    }

    public void setRespId(Long respId) {
        this.respId = respId;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getPicUrl() {
        return picUrl;
    }

    public void setPicUrl(String picUrl) {
        this.picUrl = picUrl;
    }

    /**
     * 使用mediaId来存储openId
     */
    public String getMediaId() {
        return mediaId;
    }

    /**
     * 使用mediaId来存储openId
     */
    public void setMediaId(String mediaId) {
        this.mediaId = mediaId;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getThumbMediaid() {
        return thumbMediaid;
    }

    public void setThumbMediaid(String thumbMediaid) {
        this.thumbMediaid = thumbMediaid;
    }

    public Double getLocationX() {
        return locationX;
    }

    public void setLocationX(Double locationX) {
        this.locationX = locationX;
    }

    public Double getLocationY() {
        return locationY;
    }

    public void setLocationY(Double locationY) {
        this.locationY = locationY;
    }

    public Double getScale() {
        return scale;
    }

    public void setScale(Double scale) {
        this.scale = scale;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * 使用msgid来存储appid
     * @return appid
     */
    public String getMsgId() {
        return msgId;
    }

    /**
     * 使用msgid来存储appid
     * @param msgId appid
     */
    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public String getEventkey() {
        return eventkey;
    }

    public void setEventkey(String eventkey) {
        this.eventkey = eventkey;
    }

    public String getRespmsg() {
        return respmsg;
    }

    public void setRespmsg(String respmsg) {
        this.respmsg = respmsg;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public void copyTo(WechatRequestForExport export) {
        export.setMsgId(this.getMsgId());
        export.setMediaId(this.getMediaId());
        if (Constant.OLD_USER_ID == this.getUserId()) {
            export.setUserType("旧用户");
        } else {
            export.setUserType("新用户");
        }

        if ("text".equalsIgnoreCase(this.getMsgType())) {
            export.setMsgType("文本消息");
        } else if ("event".equalsIgnoreCase(this.getMsgType())) {
            export.setMsgType("事件消息");
        } else {
            export.setMsgType(this.getMsgType());
        }
        if ("subscribe".equalsIgnoreCase(this.getEvent())) {
            export.setEvent("用户关注");
        } else if ("CLICK".equalsIgnoreCase(this.getEvent())
                || "VIEW".equalsIgnoreCase(this.getEvent())
                || "location_select".equalsIgnoreCase(this.getEvent())) {
            export.setEvent("菜单点击");
        } else {
            export.setEvent(this.getEvent());
        }
        export.setEventkey(this.getEventkey());
        export.setContent(this.getContent());
        if (StringUtils.isNotBlank(this.getRespmsg())) {
            try {
                Map<String, String> requestMap = MessageUtil.parseXml(this.getRespmsg());
                export.setRespmsg(requestMap.get("Content"));
            } catch (Exception e) {
                export.setRespmsg(this.getRespmsg());
                e.printStackTrace();
            }
        } else {
            export.setRespmsg(this.getRespmsg());
        }
        export.setCreateTime(new Date(this.getCreateTime().getTime() - 14 * 3600 * 1000));
    }
}
